<template>
  <div class="app-container">

    <div class="bigbox">
      <div>活动参与人数为{{this.groups.joinNum}}人</div>
      <div>砍价人数{{this.groups.bargainNum}}人</div>
      <div>发起砍价数{{this.groups.bargainInitiate}}人</div>
      <div>砍价成功数{{this.groups.bargainSuccess}}人</div>
      <div>支付订单额{{this.groups.orderPrice==null?"0":this.groups.orderPrice}}</div>
      <div>支付人数{{this.groups.payNum==null?"0":this.groups.payNum}}</div>
    </div>







    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单搜索" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入用户Uid"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>







    <el-table v-loading="loading" :data="sonList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="头像" align="center" prop="img">
        <template slot-scope="scope">
          <el-image :src="scope.row.img" style="width: 50px;height: 50px"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="发起用户" align="center" prop="name" />
      <el-table-column label="发起时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="帮砍人数" align="center" prop="helpNum" />
      <el-table-column label="	结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="砍价状态" align="center" prop="status">
        <template slot-scope="scope">
          {{scope.row.status=="1"?"已成功":"已失败"}}
        </template>
      </el-table-column>
      <el-table-column label="砍价金额" align="center" prop="bargainPrice" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['points:son:edit']"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改主页展示对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-table v-loading="loading" :data="grandsonList">
        <el-table-column label="id" align="center" prop="id" />
        <el-table-column label="头像" align="center" prop="img">
          <template slot-scope="scope">
            <el-image :src="scope.row.img" style="width: 50px;height: 50px"></el-image>
          </template>
        </el-table-column>
        <el-table-column label="砍价金额" align="center" prop="price" />
        <el-table-column label="砍价时间" align="center" prop="times" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.times, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listSon, getSon, delSon, addSon, updateSon } from "@/api/points/BargainGroupListSon";
import {getGrandson, listGrandson} from "@/api/points/grandson";
import {findGroupList, listGroupList} from "@/api/points/group";

export default {
  name: "Son",
  data() {
    return {
      grandsonList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedBargainGroupListGrandson: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 主页展示表格数据
      sonList: [],
      // ${subTable.functionName}表格数据
      bargainGroupListGrandsonList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        img: null,
        name: null,
        startTime: null,
        helpNum: null,
        endTime: null,
        status: null,
        bargainPrice: null,
        pid: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      id:'',

      groups:{},
    };
  },
  created() {
    if (this.$route.query.id) {
      this.id=this.$route.query.id;
    };
    this.getList(this.id);
    this.findGroup(this.id);
  },
  methods: {
    findGroup(){
      let bid = this.id;
      findGroupList(bid).then(response => {
        this.groups=response;
      })
    },
    /** 查询主页展示列表 */
    getList(id) {
      this.loading = true;
      this.queryParams.pid=id;
      console.log(this.queryParams.pid)
      listSon(this.queryParams).then(response => {
        this.sonList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        img: null,
        name: null,
        startTime: null,
        helpNum: null,
        endTime: null,
        status: null,
        bargainPrice: null,
        pid: null
      };
      this.bargainGroupListGrandsonList = [];
      this.resetForm("form");
    },
    findSonList(){

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList(this.queryParams);
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加主页展示";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      listGrandson(id).then(response => {
        this.grandsonList = response.rows;
        this.open = true;
        this.title = "查看详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.bargainGroupListGrandsonList = this.bargainGroupListGrandsonList;
          if (this.form.id != null) {
            updateSon(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSon(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除主页展示编号为"' + ids + '"的数据项？').then(function() {
        return delSon(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** ${subTable.functionName}序号 */
    rowBargainGroupListGrandsonIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** ${subTable.functionName}添加按钮操作 */
    handleAddBargainGroupListGrandson() {
      let obj = {};
      obj.img = "";
      obj.price = "";
      obj.times = "";
      this.bargainGroupListGrandsonList.push(obj);
    },
    /** ${subTable.functionName}删除按钮操作 */
    handleDeleteBargainGroupListGrandson() {
      if (this.checkedBargainGroupListGrandson.length == 0) {
        this.$modal.msgError("请先选择要删除的${subTable.functionName}数据");
      } else {
        const bargainGroupListGrandsonList = this.bargainGroupListGrandsonList;
        const checkedBargainGroupListGrandson = this.checkedBargainGroupListGrandson;
        this.bargainGroupListGrandsonList = bargainGroupListGrandsonList.filter(function(item) {
          return checkedBargainGroupListGrandson.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleBargainGroupListGrandsonSelectionChange(selection) {
      this.checkedBargainGroupListGrandson = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('points/son/export', {
        ...this.queryParams
      }, `son_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.bigbox{
  width: 100%;
  height: 200px;
  background-color: #00afff;
}
</style>
